home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / TimGA 1.2.1 / .h / CCrossMemory.h next >
Encoding:
Text File  |  1997-07-16  |  3.4 KB  |  122 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CCrossMemory.h            ©1996-97 Timo Eloranta        All rights reserved.
  3. // ===========================================================================
  4. //    This class, used by CGraphDrawing, was added to the application in the
  5. //    optimization phase to speed up the process of calculating edge crossings.
  6.  
  7. #pragma once
  8.  
  9. #include <PP_Types.h>
  10.  
  11. class CCrossMemory
  12. {
  13.     private:
  14.         UInt32        mEdgeCount;        // Nbr of edges
  15.         UInt16        mCrossTotal;    // Nbr of edge crossings
  16.  
  17.         Boolean        *mArray;        // Storage of crossing facts (bool)
  18.         Boolean        *mIterator;        // Storage scanner
  19.  
  20.         UInt32        mSize;            // Size of the storage (columns)
  21.         UInt32        mByteSize;        // Size of the storage (in bytes)
  22.  
  23.     public:
  24.                     CCrossMemory( UInt16 inEdgeCount );
  25.                     ~CCrossMemory();
  26.  
  27.         CCrossMemory &operator=( const CCrossMemory & inCM );
  28.  
  29.         void        ResetCrossTotal()
  30.                         { mCrossTotal = 0; };
  31.         Int32        GetCrossTotal() const
  32.                         { return (Int32) mCrossTotal; };
  33.  
  34.         void        ResetScanner()
  35.                         { mIterator = mArray; };
  36.         void        AdvanceScanner()
  37.                         { mIterator++; };
  38.  
  39.         void        SetCrossFact( Boolean inCrosses );
  40.         void        SetCrossFactByFlipping(    Boolean inCrosses );
  41.  
  42.         Boolean        HasStorage() const
  43.                         { return mArray != nil; };
  44. };
  45.  
  46. // ===========================================================================
  47. // • Inline Functions
  48. // ===========================================================================
  49.  
  50. // ---------------------------------------------------------------------------
  51. //        • operator=
  52. //
  53. //          Called by:    CGraphDrawing::RuntimeCopy
  54. // ---------------------------------------------------------------------------
  55.  
  56. inline CCrossMemory & 
  57. CCrossMemory::operator=( const CCrossMemory & inCM )
  58. {
  59.     mEdgeCount    = inCM.mEdgeCount;
  60.     mCrossTotal    = inCM.mCrossTotal;
  61.  
  62.     ::BlockMoveData( inCM.mArray, mArray, mByteSize );
  63.     
  64.     return *this;
  65. }
  66.  
  67. // ---------------------------------------------------------------------------
  68. //        • SetCrossFact
  69. //
  70. //          Called by:    CGraphDrawing::SmarterCountSect
  71. // ---------------------------------------------------------------------------
  72.  
  73. inline void 
  74. CCrossMemory::SetCrossFact( 
  75.     Boolean    inCrosses )
  76. {
  77.     *mIterator = inCrosses;
  78.     if ( inCrosses )
  79.         mCrossTotal++;
  80. }
  81.  
  82. // ---------------------------------------------------------------------------
  83. //        • SetCrossFactByFlipping
  84. //
  85. //          Called by:    CGraphDrawing::SmarterCountSect
  86. // ---------------------------------------------------------------------------
  87.  
  88. inline void 
  89. CCrossMemory::SetCrossFactByFlipping( 
  90.     Boolean    inCrosses ) 
  91. {
  92.     if ( *mIterator ) {                // These edges used to cross...
  93.         if ( !inCrosses ) {            // ...but don't cross anymore
  94.             *mIterator = 0;
  95.             mCrossTotal--;            // Decrease cross count by 1
  96.         }
  97.     }
  98.     else                            // These edges didn't cross before...
  99.         if ( inCrosses ) {            // ... but do now
  100.             *mIterator = 1;
  101.             mCrossTotal++;            // Increase cross count by 1
  102.         }
  103. }
  104.  
  105. // ---------------------------------------------------------------------------
  106. //        • GetBoolPtr    ( NOT USED BY THIS VERSION )
  107. // ---------------------------------------------------------------------------
  108. //    The returned pointer points to the boolean, which tells whether
  109. //    the two edges (inEdgeN1 & inEdgeN2) currently intersect.
  110.  
  111. /*
  112. inline Boolean *
  113. CCrossMemory::GetBoolPtr(
  114.     UInt16 inEdgeN1,
  115.     UInt16 inEdgeN2 ) const
  116. {
  117.     return mArray + 
  118.         ((( (inEdgeN1 - 1) * (2 * mEdgeCount - inEdgeN1) ) / 2 )
  119.                 +  inEdgeN2 - inEdgeN1 - 1 );
  120. }
  121. */
  122.